
public class MA5600TelnetTransmissionController {
	
	private String[] FindBoardAndPort(String Port)
	{
		String[] Result = new String[2];
		
		char[] boardPortBuf = new char[Port.length() - Port.lastIndexOf('/')-1]; // Finding the port in string
		Port.getChars(Port.lastIndexOf('/')+1, Port.length(), boardPortBuf, 0); // Writing to buffer Port Info
		
		char[] boardbuf = new char[Port.lastIndexOf('/') - 0]; // Finding board in string
		Port.getChars(0, Port.lastIndexOf('/'), boardbuf, 0);
		
		String portBoard = new String(boardPortBuf);
		String board = new String (boardbuf);
		
		Result[0] = board;
		Result[1] = portBoard;
		
		return Result;
	}
	
	public String[] GetPortStatus(String Port)
	{
		String[] Result = new String[8];
		String[] ParsedBoardAndPort = FindBoardAndPort(Port);
		Result[0] = "config";
		Result[1] = "undo info-center enable";
		Result[2] = "display line operation port " + ParsedBoardAndPort[0] + "/" + ParsedBoardAndPort[1];
		Result[3] = "y";
		Result[4] = "info-center enable";
		Result[5] = "quit";
		Result[6] = "quit";
		Result[7] = "y";
		return Result;
	}
	
	public String[] GetPortPVC(String Port)
	{
		String[] Result = new String[7];
		String[] ParsedBoardAndPort = FindBoardAndPort(Port);
		Result[0] = "config";
		Result[1] = "undo info-center enable";
		Result[2] = "display interface adsl " + ParsedBoardAndPort[0] + "/" + ParsedBoardAndPort[1];
		Result[3] = "info-center enable";
		Result[4] = "quit";
		Result[5] = "quit";
		Result[6] = "y";
		return Result;
	}
	
	public String[] SetPortReset(String Port)
	{	
		String[] Result = new String[10];
		String[] ParsedBoardAndPort = FindBoardAndPort(Port);
		Result[0] = "config";
		Result[1] = "undo info-center enable";
		Result[2] = "interface adsl " + ParsedBoardAndPort[0];
		Result[3] = "deactivate " + ParsedBoardAndPort[1];
		Result[4] = "activate " + ParsedBoardAndPort[1];
		Result[5] = "quit";
		Result[6] = "info-center enable";
		Result[7] = "quit";
		Result[8] = "quit";
		Result[9] = "y";
		return Result;
	}
	
	public String[] GetWholePortInformation (String Port)
	{
		
		String[] Result = new String[15];
		String[] ParsedBoardAndPort = FindBoardAndPort(Port);
		Result[0] = "config";
		Result[1] = "undo info-center enable";
		Result[2] = "display mac-address adsl  " + ParsedBoardAndPort[0] + "/" + ParsedBoardAndPort[1]; 
		Result[3] = "display interface adsl " + ParsedBoardAndPort[0] + "/" + ParsedBoardAndPort[1];
		Result[4] = "display line operation port " + ParsedBoardAndPort[0] + "/" + ParsedBoardAndPort[1];
		Result[5] = "y";
		Result[6] = "scroll 512";
		Result[7] = "display adsl line-profile";
		Result[8] = "\n";
		//Result[9] = "\n";
		Result[10] = "scroll 50";
		       Result[11] = "info-center enable"; //ex 6
		Result[12] = "quit";
		Result[13] = "quit";
		Result[14] = "y";
		return Result;
	}
	
	public String[] SetPortRateProfile(String Port, String ProfileIndex)
	{
		String[] Result = new String[10];
		String[] ParsedBoardAndPort = FindBoardAndPort(Port);
		Result[0] = "config";
		Result[1] = "undo info-center enable";
		Result[2] = "interface adsl " + ParsedBoardAndPort[0];
		Result[3] = "deactivate " + ParsedBoardAndPort[1];
		Result[4] = "activate " + ParsedBoardAndPort[1] + " profile-index " + Integer.parseInt(ProfileIndex); //activate 45 profile-index index
		Result[5] = "quit";
		Result[6] = "info-center enable";
		Result[7] = "quit";
		Result[8] = "quit";
		Result[9] = "y";
		return Result;
	}
	
	// Calling CreateCommand Without changing Profile on 5600
	public String[] CreateCommand(String[] ParsedCommand)
	{
		if (ParsedCommand[1].contains("GetPortStatus"))return GetWholePortInformation(ParsedCommand[3]);
		else if (ParsedCommand[1].contains("GetPortPVC"))return GetWholePortInformation(ParsedCommand[3]);
		else if (ParsedCommand[1].contains("SetPortReset")) return SetPortReset(ParsedCommand[3]);
		else if (ParsedCommand[1].contains("SetPortRateProfile")) return SetPortRateProfile(ParsedCommand[3], ParsedCommand[4]);
		
		return null;
	}
	
	public String ParseReply( String ServerReply)
	{
		return "";
	}
}
